package com.zlm.udpThread;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

/**
 * @Author: 郑
 * url下载
 */
public class UrlDOwn {

    public static void main(String[] args) throws IOException {
        URL url = new URL("http://localhost:8080/aaa/a.txt");
        //连接到资源
        URLConnection urlConnection = url.openConnection();
        InputStream is = urlConnection.getInputStream();
        FileOutputStream fos = new FileOutputStream("abc.txt");
        byte[] bytes = new byte[1024];
        int len;
        while ((len = is.read(bytes)) != -1){
            fos.write(bytes,0,len);
            fos.flush();
        }

        fos.close();
        is.close();

    }
}
